<template>
	<view class="container">
		<image mode="widthFix" class="logo" src="../../static/logo.png"></image>
		<u-loading-icon size="36" iconColor="#ccc" status="loading" loadingText=""></u-loading-icon>
	</view>
</template>

<script>
import { msgJump } from '@/utils/jump.js';
export default {
	data() {
		return {
			loading: false,
			dataList: [],
			hrefData: ''
		};
	},
	onLoad(e) {
		console.log('页面显示执行block', e);
		if (e.mark) {
			this.hrefData = e;
		}
		this.wxGetOpenId();
	},
	methods: {
		onRefresh() {
			this.$refs.paging.complete();
		},
		wxGetOpenId(code) {
			let that = this;
			let app = getApp();
			uni.login({
				timeout: 5000,
				success(login) {
					that.$Api
						.wxGetOpenId({
							code: login.code,
							openid: ''
						})
						.then(async (res) => {
							console.log(res, 'openid');
							if (res.code == 200) {
								uni.setStorageSync('userInfo', res.data);
								if (res.data.empower == 0) {
									uni.reLaunch({
										url: '/pages/login/login'
									});
									return;
								}
								let menu = await that.$hApi.getUserMenuList({
									admin_id: res.data.id
								});
								let organization = await that.$Apipc.getOrganizationDetails({
									id: res.data.position_id
								});
								console.log(menu, 'menuList');
								console.log(organization, 'organizationList');
								// 用户菜单
								if (menu.code == 200) {
									let arr = [];
									for (let i = 0; i < menu.data.length; i++) {
										if (menu.data[i].vue_path != '/configManagement') {
											arr.push(menu.data[i].vue_path);
											if (menu.data[i].nodes) {
												for (let j = 0; j < menu.data[i].nodes.length; j++) {
													arr.push(menu.data[i].nodes[j].vue_path);
													if (menu.data[i].nodes[j].nodes) {
														for (let k = 0; k < menu.data[i].nodes[j].nodes.length; k++) {
															arr.push(menu.data[i].nodes[j].nodes[k].vue_path);
														}
													}
												}
											}
										}
									}
									console.log(arr, '所有菜单path');
									app.globalData.menuList = arr;
								}
								// 字段权限
								if (organization.code == 200) {
									let field_permissions = organization.data[0].field_permissions ? JSON.parse(organization.data[0].field_permissions) : '';
									if (field_permissions) {
										console.log(field_permissions, '所有字段权限');
										app.globalData.fieldPermissions = field_permissions;
									}
								}
								// 公众号消息判断
								if (that.hrefData) {
									console.log('公众号进来', that.hrefData);
									let path = msgJump(that.hrefData);
									// 跳转处理
									uni.reLaunch({
										url: path
									});
									return;
								}
								uni.reLaunch({
									url: '/pages/index/index'
								});
							}
						})
						.catch((err) => {
							console.log(err);
						});
				},
				fail(err) {
					console.log(err);
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.container {
	width: 100%;
	height: 100vh;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;

	.logo {
		width: 200rpx;
		margin-top: -200rpx;
		margin-bottom: 30rpx;
	}
}
</style>
